package com.polymathcoder.dpastry.core.util;

import com.polymathcoder.dpastry.api.Callback;
import com.polymathcoder.dpastry.api.CallbackRunnableFuture;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * CallbackFutureTask
 * <p/>
 * An extension of FutureTask that includes a Callback
 *
 * @author Drew Botwinick
 * @version 0.0.1
 */
public class CallbackFutureTask<V> extends FutureTask<V> implements CallbackRunnableFuture<V> {

    protected Callback<V> callback = null;

    public CallbackFutureTask(Callable<V> vCallable, Callback<V> vCallback) {
        super(vCallable);
        setCallback(vCallback);
    }

    @Override
    public void setCallback(Callback<V> vCallback) {
        this.callback = vCallback;
    }

    @Override
    public boolean hasCallback() {
        return callback != null;
    }

    @Override
    public Callback<V> getCallback() {
        return callback;
    }
}
